package _3sort.src;

//将数组中小于target的值放左边，等于的放中间，大于的放右边
public class _5problem_helanguoqi {
    public static void main(String[] args) {
        int[] nums = {2, 5, 6, 2, 4, 3, 8, 9, 4, 6, 5, 3, 6};
        int target=5;
         paixu(nums, target);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i]+" ");
        }
    }

    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    private static void paixu(int[] nums, int target) {
        int first=0;
        int last = nums.length - 1;
        int i=0;
        while (i <= last) {
            if (nums[i] == target) {
                i++;
            } else if (nums[i] < target) {
                swap(nums,first++, i++);
            }else {
                swap(nums,i, last--);//根据实际判断相关的索引
            }
        }
    }
}
